package com.youlai.system.controller;

import com.youlai.system.common.result.Result;
import com.youlai.system.common.util.CommUtils;
import com.youlai.system.model.entity.TimeProgram;
import com.youlai.system.service.TimeProgramService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "900.时间程序")
@RestController
@RequestMapping("/api/v1/timeprogram")
@RequiredArgsConstructor
public class TimeProgramController {

    private final TimeProgramService timeProgramService;

    @GetMapping
    @Operation(summary = "获取所有时间程序")
    public Result<List<TimeProgram>> getAllTimeProgram(){
        List<TimeProgram> timeProgramList = timeProgramService.list();
        return Result.success(timeProgramList);
    }
    @PutMapping
    @Operation(summary = "更新信息")
    public Result<Boolean> updateTimeProgram( @RequestBody TimeProgram timeProgram) {
        timeProgram.setTime(CommUtils.getCurrentDateTime());
        return Result.judge(timeProgramService.updateById(timeProgram));
    }


}